package org.csmzxy.class2333;

public class Example03 {
   public static void main(String[] args) {
       int limit = 20;
       long sum = calculateFibonacciSum(limit);
       System.out.println("斐波那契数列前" + limit +"项之和为:" + sum);
   }


   public static long calculateFibonacciSum(int n) {
       if (n <= 0) {
           return 0;
       }
       if (n == 1) {
           return 1;
       }
       long first = 1;
       long second = 1;
       long sum = 2;
       for (int i = 3; i <= n; i++) {
           long next = first + second;
           sum += next;
           first = second;
           second = next;
       }
       return sum;
   }
}
